// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Aggregations
{
	public sealed partial class DateRangeExpression
	{
		[JsonInclude]
		[JsonPropertyName("from")]
		public Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? From { get; set; }

		[JsonInclude]
		[JsonPropertyName("key")]
		public string? Key { get; set; }

		[JsonInclude]
		[JsonPropertyName("to")]
		public Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? To { get; set; }
	}

	public sealed partial class DateRangeExpressionDescriptor : SerializableDescriptorBase<DateRangeExpressionDescriptor>
	{
		internal DateRangeExpressionDescriptor(Action<DateRangeExpressionDescriptor> configure) => configure.Invoke(this);
		public DateRangeExpressionDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? FromValue { get; set; }

		private string? KeyValue { get; set; }

		private Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? ToValue { get; set; }

		public DateRangeExpressionDescriptor From(Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? from)
		{
			FromValue = from;
			return Self;
		}

		public DateRangeExpressionDescriptor Key(string? key)
		{
			KeyValue = key;
			return Self;
		}

		public DateRangeExpressionDescriptor To(Elastic.Clients.Elasticsearch.Aggregations.FieldDateMath? to)
		{
			ToValue = to;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (FromValue is not null)
			{
				writer.WritePropertyName("from");
				JsonSerializer.Serialize(writer, FromValue, options);
			}

			if (!string.IsNullOrEmpty(KeyValue))
			{
				writer.WritePropertyName("key");
				writer.WriteStringValue(KeyValue);
			}

			if (ToValue is not null)
			{
				writer.WritePropertyName("to");
				JsonSerializer.Serialize(writer, ToValue, options);
			}

			writer.WriteEndObject();
		}
	}
}